import OSS from "ali-oss";
import request from '@/utils/request'


export async function createOss(){
  let res=await request({
    url:"/oss/oss/getStsToken",
    method:"get"
  })
  const {accessKeyId,accessKeySecret,securityToken} = res.data;
  let client = new OSS({
    region:"oss-cn-beijing",
    accessKeyId: accessKeyId,
    accessKeySecret:accessKeySecret,
    stsToken:securityToken,
    bucket: 'xsjoss', // 填写Bucket名称。
    refreshSTSToken: async () => {
      let info=await request({
        url:"/oss/oss/getStsToken",
        method:"get"
      })
      return {
        accessKeyId: info.data.accessKeyId,
        accessKeySecret: info.data.accessKeySecret,
        stsToken: info.data.securityToken
      }
    },
    // 刷新临时访问凭证的时间间隔，单位为毫秒。
    refreshSTSTokenInterval: 300000,
  })
  return client;
}







